The present invention relates to a computer implemented method of compiling computer program loops containing calculations dealing with data arrays.
Prior art methods of compiling computer programs will be explained using program examples. A variety of compiling methods are well known in the prior art. For example A. Aho and J. Ullman, Principles of Compiler Design, Addison-Wesley Pub. Co., pp. 557-60, discloses a FORTRAN H compiler and a C compiler. Both illustrate the basic structural features of a compiler including lexical and syntactic analysis, code generation and optimization.
FIG. 17 is the FORTRAN coding for program example 1, FIG. 18 is the FORTRAN coding for program example 2, FIG. 19 is the dummy object coding for program example 1, and, FIG. 20 is the dummy object coding for program example 2. Such dummy object coding is well known in the prior art. For example, W. Barrett and J. Couch, Compiler Construction Theory and Practice, Science Research Assocs., Inc. pp 563-69, illustrates the use of dummy object code to describe to others in the art their algorithms. See also U.S. Pat. No. 4,719,867, Watanabe.
The programming sequences shown in FIGS. 19 and 20 each being with an Initial Loop Setting instruction, namely:
LOOP ENTRY x=y, z, w PA1 In this instruction, the index is x, the initial value is y, the final value is z and the increment is w. PA1 LOAD #x, reg y PA1 In this instruction, the memory content of location x is loaded into register y. PA1 ADD reg x, reg y, reg z PA1 reg z=reg x+reg y. PA1 Add reg x, #y, reg z PA1 reg z=reg x+#y. PA1 STORE reg x, #y PA1 MOVE reg x, reg y PA1 LOOP_RETURN x=x+y, z
A Loading Register instruction is also included, namely:
A first Addition instruction:
performs the following operation:
while a second Addition instruction:
performs the following operation:
A Storing Register instruction:
results in the contents of register x being stored in memory y.
An Inter-Register Move instruction:
results in the contents of register x being copied into register y.
In a Post Processing instruction:
the value of X is added to the value of Y and program execution skips to z. An appropriate value of X results in an exiting of the loop.
If the exemplary computer program which is shown in FIG. 17 (Program example 1) is compiled by well known prior art methods, the result is as in FIG. 19. As shown, loop execution is initialized. Next, at the start of the loop body, B(I-1) and B(I) are loaded and added, then B(I+1) is also added. Finally, the result is stored in A(I) and loop return is executed. If the exemplary computer program which is shown in FIG. 18 (Program example 2) is compiled by well known prior art methods, the result is as in FIG. 20. As shown, loop execution is initialized. Then, at the start of the loop body, A(I-1) is loaded and added to instant value 1. The result is stored in A(I). Then A(I+1) is also loaded and added to instant value 2. Finally, the result is stored in A(I-1) and loop return is executed.
As related above, in accordance with prior art methods, the same data is loaded and stored a plurality of times when the index values are different. For example, in the dummy coding for program example 1, the value for B(3) is loaded as B(I=1) when I=2, as B(I) when I=3, and, as B(I-1) when I=4. Furthermore, in the dummy coding for program example 2, the value for A(3) is stored as A(I) when I=3, and as A(I-1) when I=4; and loaded as A(I-1) when I=4 and as A(I+1) when I=2. Thus, in well known prior art methods of compiling, there is more accessing of memory than is necessary.